package com.aspose.cells;

import java.util.Iterator;

class zgr implements zaft {
   private int a;
   private int b;
   private Workbook c;
   private zbvx d;
   private zbpx e;
   private boolean f;
   private boolean g;
   private int h;
   private byte[] i;
   private boolean j;
   private int[] k;
   private int l;
   private boolean m;
   private int[] n;
   private int[] o;
   private zfv p;
   private Cells q;
   private boolean r;
   private boolean s;
   private boolean t;
   private zp u;
   private zp v;
   private int w;
   private int x;
   private int y;
   private int z;
   private int A;

   zgr(Workbook var1, SaveOptions var2) {
      int var3;
      short var4;
      super();
      this.f = false;
      this.j = true;
      this.m = true;
      this.p = new zfv();
      this.c = var1;
      this.d = var1.getWorksheets().B();
      this.m = true;
      var3 = 1048575;
      var4 = 16383;
      label79:
      switch(var2.getSaveFormat()) {
      case 1:
      case 11:
      case 13:
      case 20:
      case 21:
      case 22:
      case 30:
         this.m = false;
         this.j = false;
         break;
      case 2:
      case 3:
      case 4:
      case 10:
      case 14:
      case 15:
      case 18:
      case 19:
      case 23:
      case 24:
      case 25:
      case 26:
      case 27:
      case 28:
      case 29:
      default:
         this.j = true;
         break;
      case 5:
         var3 = 65535;
         var4 = 255;
         this.f = true;
         this.j = this.d.a(var2.a(), 1) > 0;
         break;
      case 6:
      case 7:
      case 8:
      case 9:
      case 16:
         this.f = true;
         this.j = this.d.a(var2.a(), 1) > 0;
         Iterator var5 = this.c.getWorksheets().getNames().iterator();

         while(true) {
            if (!var5.hasNext()) {
               break label79;
            }

            Name var6 = (Name)var5.next();
            var6.g(var6.i().replace('\u0015', '_'));
         }
      case 12:
      case 17:
         this.m = true;
         this.j = this.d.a(var2.a(), 0) > 0;
      }

      this.a = var3;
      this.b = var4 + 1;
      if (this.m) {
         this.e = var1.getWorksheets().g;
         int var7;
         if (!this.e.b()) {
            this.m = false;

            for(var7 = var1.getWorksheets().getCount() - 1; var7 > -1; --var7) {
               if (var1.getWorksheets().get(var7).getCells().getPreserveString()) {
                  this.m = true;
                  break;
               }
            }
         }

         if (this.m) {
            this.n = new int[this.e.a.length];
            this.o = new int[this.e.a.length];

            for(var7 = 0; var7 < this.o.length; this.o[var7] = var7++) {
               ;
            }
         }
      }

      if (this.j) {
         this.k = this.d.c();
         if (this.k == null) {
            this.j = false;
         } else {
            this.l = this.k[0];
         }
      }

      this.g = false;
      if (this.f) {
         this.i = this.d.d();
         if (this.i == null) {
            this.f = false;
         } else {
            this.h = this.i[0] & 255;
            if (this.h == 0) {
               this.g = true;
               this.h = this.i[15] & 255;
            }
         }
      }

   }

   public boolean a(zp var1, int var2) {
      if (this.u != var1) {
         this.u = var1;
         this.b();
      }

      this.w = var2;
      this.d();
      return false;
   }

   zack a() {
      zack var1 = null;
      if (!this.m && !this.j && !this.f) {
         return null;
      } else {
         int var2 = this.c.getWorksheets().getCount() - 1;

         zahl var12;
         while(var2 > -1) {
            this.q = this.c.getWorksheets().get(var2).getCells();
            this.r = this.q.getPreserveString();
            if (this.f) {
               this.s = (this.h & 3) == 0;
               this.t = (this.h & 12) == 0;
            }

            if (this.j || this.g) {
               ColumnCollection var3 = this.q.getColumns();
               int var4;
               if (var3.b != null) {
                  var4 = var3.b.c();
                  if (this.j && var4 > this.l) {
                     var4 = this.k[var4];
                     var3.b.c(var4);
                  }

                  if (this.f && var4 > -1) {
                     int var5 = this.i[var4] & 255;
                     if (this.s) {
                        this.s = (var5 & 5) == 0;
                     }

                     if (this.t) {
                        this.t = (var5 & 10) == 0;
                     }
                  }
               }

               for(var4 = var3.getCount() - 1; var4 > -1; --var4) {
                  this.a(var3.getColumnByIndex(var4));
               }
            }

            if (this.f) {
               if (!this.s) {
                  if (var1 == null) {
                     var1 = new zack(this.c);
                     var1.f = new boolean[var1.d];
                     com.aspose.cells.a.c.zc.a(var1.f, 0, var1.d, false);
                  } else if (var1.f == null) {
                     var1.f = new boolean[var1.d];
                     com.aspose.cells.a.c.zc.a(var1.f, 0, var1.d, false);
                  }

                  var1.f[var2] = true;
               }

               if (!this.t) {
                  if (var1 == null) {
                     var1 = new zack(this.c);
                     var1.g = new boolean[var1.d];
                     com.aspose.cells.a.c.zc.a(var1.g, 0, var1.d, false);
                  } else if (var1.g == null) {
                     var1.g = new boolean[var1.d];
                     com.aspose.cells.a.c.zc.a(var1.g, 0, var1.d, false);
                  }

                  var1.g[var2] = true;
               }
            }

            if (this.m || this.f) {
               this.q.d = new zkt(this.q, 16383);
            }

            zr var10 = this.q.f();
            zahl var13 = var10.b();
            this.z = -1;

            while(true) {
               this.w = var13.a();
               if (this.w < 0) {
                  if (this.f) {
                     this.q.m();
                     if ((this.y & 2) == 0 && (this.h & 1) != 0 && this.z > -1 && this.z < this.a) {
                        this.v.a(1, zbbj.f(this.v.l(1), true));
                     }
                  } else if (this.m) {
                     this.q.m();
                  }

                  --var2;
                  break;
               }

               this.u = var10.f(this.w);
               this.b();
               if (this.u.a() > 0) {
                  var12 = this.u.b();

                  while(true) {
                     this.w = var12.a();
                     if (this.w < 0) {
                        break;
                     }

                     this.d();
                  }
               }

               this.c();
            }
         }

         if (!this.m) {
            return var1;
         } else {
            if (this.e.a.length != this.o.length) {
               this.o = new int[this.e.a.length];
            }

            var2 = this.e.a(this.n, this.o);
            if (var2 > 0) {
               label165:
               for(int var11 = this.c.getWorksheets().getCount() - 1; var11 > -1; --var11) {
                  this.q = this.c.getWorksheets().get(var11).getCells();
                  zr var14 = this.q.f();
                  var12 = var14.b();

                  do {
                     zp var6;
                     int var8;
                     do {
                        do {
                           var8 = var12.a();
                           if (var8 < 0) {
                              continue label165;
                           }

                           var6 = var14.f(var8);
                        } while(var6.a() <= 0);
                     } while(var6.c());

                     zahl var7 = var6.b();

                     while(true) {
                        var8 = var7.a();
                        if (var8 < 0) {
                           break;
                        }

                        if (var6.h(var8) == 4) {
                           int var9 = var6.j(var8);
                           if (var9 != this.o[var9]) {
                              var6.k(var8, this.o[var9]);
                              --var2;
                              if (var2 == 0) {
                                 break;
                              }
                           }
                        }
                     }
                  } while(var2 != 0);
               }
            }

            return var1;
         }
      }
   }

   private void a(Column var1) {
      int var2 = var1.c();
      if (this.j && var2 > this.l) {
         var2 = this.k[var2];
         var1.c(var2);
      }

      if (this.f && var2 > -1) {
         int var3 = this.i[var2] & 255;
         if (this.s) {
            this.s = (var3 & 5) == 0;
         }

         if (this.t) {
            this.t = (var3 & 10) == 0;
         }
      }

   }

   private void b() {
      this.x = -1;
      if (this.j) {
         this.x = this.u.i();
         if (this.x > this.l) {
            this.x = this.k[this.x];
            this.u.k(this.x);
            if (this.x != 15 && !Row.b(this.u)) {
               this.x = 15;
            }
         }
      }

      if (this.g) {
         if (this.u.h() != this.z + 1) {
            this.z = this.u.h();
            this.v = null;
            if (this.h != 0) {
               if (this.u.a() == this.b) {
                  this.y = 0;
               } else {
                  this.y = this.h;
                  this.y &= 12;
                  if ((this.h & 4) == 0 && this.z > 0 && (this.h & 1) != 0) {
                     this.y |= 12;
                  }
               }
            } else {
               this.y = 0;
            }
         } else {
            ++this.z;
            this.y <<= 2;
         }

         if ((this.y & 15) != 15) {
            if (this.x < 0) {
               this.x = Row.e(this.u);
            }

            this.b(this.x);
         }
      }

   }

   private void c() {
      if (this.f) {
         byte var1;
         if ((this.y & 8) != 0 && this.v != null) {
            var1 = this.v.l(1);
            if (!zbbj.h(var1)) {
               this.v.a(1, zbbj.f(var1, true));
            }
         }

         var1 = zbbj.g(this.u.l(1));
         if ((this.y & 6) != 0) {
            var1 = zbbj.e(var1, (this.y & 4) != 0);
            var1 = zbbj.f(var1, (this.y & 2) != 0);
            this.u.a(1, var1);
         }

         this.v = this.u;
      }

   }

   private void d() {
      this.A = -1;
      if (this.m) {
         zfv var3;
         switch(this.u.h(this.w)) {
         case 0:
         case 3:
            this.e();
            break;
         case 1:
         case 2:
         default:
            if (this.r) {
               boolean var7 = false;
               var3 = this.u.a(this.w, this.p, 7);
               this.A = var3.b;
               if (this.A < 0) {
                  this.a(var3.a);
               } else if (this.j && this.A > this.l) {
                  this.A = this.k[this.A];
                  var3.b = this.A;
                  var7 = true;
               }

               if (this.g && (this.y & 15) != 15) {
                  this.b(this.A);
               }

               Style var6 = this.d.a(this.A);
               zayy var8 = this.e.a(Cell.a(this.q, var6, var3));
               if (var8.e < this.n.length) {
                  ++this.n[var8.e];
               }

               if (var3.c == 5) {
                  this.q.b.b(((zyi)var3.d).a);
               }

               var3.c = 4;
               var3.d = var8;
               if (var7) {
                  this.u.b(this.w, var3, 6);
               } else {
                  this.u.b(this.w, var3);
               }
            } else {
               this.e();
            }
            break;
         case 4:
            var3 = null;
            boolean var4 = false;
            int var1;
            zayy var2;
            if (!this.j && !this.g) {
               var1 = this.u.j(this.w);
               var2 = this.e.a[this.o[var1]];
            } else {
               var3 = this.u.a(this.w, this.p, 7);
               this.A = var3.b;
               if (this.j && this.A > this.l) {
                  this.A = this.k[this.A];
                  var3.b = this.A;
                  var4 = true;
               }

               if (this.g && (this.y & 15) != 15) {
                  if (this.A < 0) {
                     this.a(var3.a);
                  }

                  this.b(this.A);
               }

               var2 = (zayy)var3.d;
               var1 = var2.e;
            }

            if (var2.f()) {
               zbap var5 = (zbap)var2;
               if (!var5.j()) {
                  if (var3 == null) {
                     this.A = this.u.g(this.w);
                  }

                  if (this.A < 0) {
                     if (this.x < 0) {
                        this.x = Row.e(this.u);
                     }

                     if (this.x == 15) {
                        this.A = this.q.e(var3 == null ? this.u.a(this.w) : var3.a);
                        if (this.A < 0) {
                           this.A = 15;
                        }
                     } else {
                        this.A = this.x;
                     }
                  }

                  var2 = this.e.a(var5, this.d.a(this.A).getFont().j(), this.c.getWorksheets());
                  if (var2.e != var5.e) {
                     if (var4) {
                        this.u.b(this.w, var3, 6);
                        var4 = false;
                     } else {
                        this.u.k(this.w, var2.e);
                     }

                     this.o[var1] = var2.e;
                  }
               }
            }

            if (var4) {
               this.u.j(this.w, var3.b);
            }

            ++this.n[var2.e];
         }
      } else {
         this.e();
      }

   }

   private void a(int var1) {
      if (this.x < 0) {
         this.x = Row.e(this.u);
      }

      if (this.x == 15) {
         this.A = this.q.e(var1);
         if (this.A < 0) {
            this.A = 15;
         }
      } else {
         this.A = this.x;
      }

   }

   private void e() {
      if (this.g) {
         zfv var1 = this.u.a(this.w, this.p, 3);
         this.A = var1.b;
         if (this.A < 0) {
            this.a(var1.a);
         } else if (this.j && this.A > this.l) {
            this.A = this.k[this.A];
            this.u.j(this.w, this.A);
         }

         this.b(this.A);
      } else if (this.j) {
         this.A = this.u.g(this.w);
         if (this.A > this.l) {
            this.A = this.k[this.A];
            this.u.j(this.w, this.A);
         }
      }

   }

   private void b(int var1) {
      this.y |= this.i[var1];
   }
}
